package com.lu.pojo.thread;

/**
 * @author luzhenfang
 * @date 2020 05 23
 * @description 多线程同时操作同一个资源 造成线程不安全 数据紊乱
 */
class TestThread implements Runnable{
    private int tickNums = 10;
    @Override
    public void run() {
        while (true) {
            if(tickNums<=0){
                break;
            }
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"-->拿到了第"+tickNums--+"票");
        }
    }
}


public class ThreadBlock {
    public static void main(String[] args) {
        TestThread thread = new TestThread();

        new Thread(thread,"小明").start();
        new Thread(thread,"小华").start();
        new Thread(thread,"小张").start();
    }
}
